package com.atguigu.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.atguigu.entity.Permission;
import com.atguigu.service.PermissionService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

/**
 * @author lhh
 * @ClassName PermissionController
 * @date 2022/9/29 18:39
 */
@Controller
@RequestMapping("permission")
public class PermissionController {

    @Reference
    private PermissionService permissionService;

    @GetMapping
    public String getFindMeu(Model model){
        List<Permission> list = permissionService.findAllMenu();
        model.addAttribute("list",list);
        return "permission/index";
    }

    @GetMapping("create")
    public String create(Model model,Permission permission){
        model.addAttribute("permission",permission);
        return "permission/create";
    }

    @PostMapping("save")
    public String save(Permission permission){
        permissionService.save(permission);
        return "common/successPage";
    }

    @GetMapping("edit/{id}")
    public String getById(@PathVariable Long id,Model model){
        Permission permission = permissionService.getById(id);
        model.addAttribute("permission",permission);
        return "permission/edit";
    }

    @PostMapping("update")
    public String update(Permission permission){
        permissionService.update(permission);
        return "common/successPage";
    }

    @GetMapping("/delete/{id}")
    public String delete(@PathVariable Long id){
        permissionService.remove(id);
        return "redirect:/permission";
    }
}
